package cn.thirdplatform.controller;

import cn.thirdplatform.entity.po.User;
import cn.thirdplatform.service.UserService;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import simon.dubbo.api.DemoService;

/**
 * @author simon
 * @date 2019/4/30 16:10
 * @copyright:
 * @modifier
 * @motto a no talent, people who have to study hard
 */
@Slf4j
@RestController
@RequestMapping(value = "/hello")
public class ThirdMtController {

    @Autowired
    private UserService userService;
    @Reference(check = false)
    private DemoService demoService;

    /**
     * mybatis
     *
     * @param userId
     * @return
     */
    @GetMapping(value = "/a")
    public User hello(String userId) {
        User user = userService.findById(userId);
        log.info("result:[{}]", JSONObject.toJSONString(user));
        return user;
    }

    /**
     * dubbo 服务调用
     *
     * @return
     */
    @GetMapping(value = "/a1")
    public String hello1() {
        String result = demoService.sayHello();
        log.info("result:[{}]", result);
        return result;
    }
}
